// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
const voiceCollection = db.collection('voice')
const userCollection = db.collection('user')

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  const voiceId = event.voiceid || ''
  let voice = {}

  if (voiceId == '')  return

  await voiceCollection.doc(voiceId).get().then(res => {
    voice = res.data
  })

  await userCollection.where({
    _openid: voice._openid
  }).get().then(res => {
    voice.userInfo = res.data[0]
  })

  return voice
}